package com.jbinfo.qingcaowan.studyManager.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jbinfo.common.utils.DataTables;
import com.jbinfo.common.utils.UUIDUtils;
import com.jbinfo.qingcaowan.studyManager.dao.BookChapterManagerDao;
import com.jbinfo.qingcaowan.studyManager.dto.BookChapterModel;
import com.jbinfo.qingcaowan.studyManager.entity.BookChapter;
import com.jbinfo.qingcaowan.studyManager.service.BookChapterManagerService;
/**
 * 
* @ClassName: UserServiceImpl 
* @Description: TODO 用户管理service实现类
* @author ZhangLei 
* @date 2016年6月22日 上午10:23:02
 */
@Service
public class BookChapterManagerServiceImpl implements BookChapterManagerService {

	@Autowired
	private BookChapterManagerDao bookChapterManagerDao;

	@Override
	public BookChapter getBookChapterInfo(String chapterId) {
		BookChapter bookChapter = new BookChapter();
		bookChapter.setChapterId(chapterId);
		return bookChapterManagerDao.getBookChapterInfo(bookChapter);
	}

	@Override
	public int editBookChapter(BookChapter bookChapter) {
		return bookChapterManagerDao.editBookChapter(bookChapter);
	}

	@Override
	public int delBookChapter(String chapterId) {
		return bookChapterManagerDao.delBookChapter(chapterId);
	}

	@Override
	public DataTables<BookChapter> getChapterList(BookChapterModel bookChapterModel) {
		String today = bookChapterModel.getCreateTime();
		bookChapterModel.setCreateTime1(today+" 00:00:00");
		bookChapterModel.setCreateTime2(today+" 23:59:59");
		List<BookChapter> tList = bookChapterManagerDao.getChapterList(bookChapterModel);
		for(int i=0;i<tList.size();i++){
			tList.get(i).setNo((i+1)+"");
		}
		return DataTables.combinTotalRecords(tList);
	}
	
	@Override
	public void save(BookChapter bookChapter) {
		//处理章节主键
		String chapterId = UUIDUtils.create();
		bookChapter.setChapterId(chapterId);	
		bookChapterManagerDao.save(bookChapter);
	}

	@Override
	public List<BookChapter> queryChapterList(BookChapter bookChapter) {
		return bookChapterManagerDao.queryChapterList(bookChapter);
	}

	@Override
	public List<BookChapter> getChapterByCode(BookChapter bookChapter) {
		return bookChapterManagerDao.getChapterByCode(bookChapter);
	}

}
